﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" id="teacherForm">
<head>
    <title>教室设定</title>
    <style type="text/css">
  	.tableout {color:#08478A; border-color:#CCC}
	</style>
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";

    $(function (){
    
    	$("#dateF").ligerDateEditor();
    	$("#dateT").ligerDateEditor();
    	
        mainform=$("#mainform");
          
        $("#crmCode").ligerTextBox({width:180});
        $("#crmTitle").ligerTextBox({width:180});
        $("#crmAddress").ligerTextBox({width:180});
        $("#dateF").ligerTextBox({width:180});
        $("#dateT").ligerTextBox({width:180});
        
		$('input[name^="cls-start"]').ligerTextBox({width:45});
		$('input[name^="cls-end"]').ligerTextBox({width:45});
		
        //如果是修改视图,主键不可编辑
        //if(viewType=="modify"){
        	 $("#crmId").attr("readonly", "readonly").removeAttr("validate");
        //}
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }
        
        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : ("add" == viewType ? save : confirm));
        
        //调整form-bar
        $(".form-bar").css("width","680px");         
		
        if (viewType != 'detail')
        {
	        $('#crmClassNum').bind('change', function() {  
	            for(var i = 1; i <= 10; i++) {   
	                if (i <= $(this).val()) {
	                	$('#cls-' + i ).find("td").find("input[type='text']").each(function(i) {						
	                        $(this).removeAttr('disabled');
	                        
	                        if ('dis-' == $(this).attr('name').substring(0, 4)) {
	                            $(this).attr('name', $(this).attr('name').substring( 4, $(this).attr('name').length ) );
	                        }  
	                    });
	                } else {
	                    $('#cls-' + i ).find("td").find("input[type='text']").each(function(i) {
	                        $(this).attr('disabled','disabled');
	                        
	                        if ('dis-' != $(this).attr('name').substring(0, 4)) {
	                            $(this).attr('name', 'dis-' + $(this).attr('name') ); 
	                        } 
	                    });
	                }
	            }                    
	        });
	        
	        $('#crmClassNum').trigger('change');
        }
        else
        {
        	 for(var i = 1; i <= 10; i++) { 
        		 $('#cls-' + i ).find("td").find("input[type='text']").each(function(i) {
                     $(this).attr('disabled','disabled');
        		 });
        	 }
        }
    });
   	
    function confirm() {
    	$.ligerDialog.confirm('修改教室资料会清空所有相关课程资料，是否确定修改？', function (confirm) {
            if (confirm)
            	save();
        });
    }
    
    function save(){
        LG.submitForm(mainform, function (result) {
        	if(typeof(result)=="string"){
        		result=eval("("+result+")");
        	}
            if (!result.success) {
                LG.showError('错误:' + result.message);
            }
            else { 
                LG.showSuccess('保存成功', function () { 
                   LG.callParent("crmList");
                });
            }
        });
    }
    
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
    
 </script> 
</head>

<body>
    <form name="mainform" method="post"  id="mainform" action="${ctx }/qso/croom/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <table cellpadding="0" cellspacing="0" class="l-table-edit"  style="width: 95%; margin-left:15px;">
            <tr>
                <td style="width:15%; padding-bottom: 0px;" align="right" class="l-table-edit-td">教室代码:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                	${command.crmId}
                	<input name="crmId" type="hidden" id="crmId" value="${command.crmId}" ltype="text" />
                </td>
                <td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">教室编号:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                	<input name="crmCode" type="text" id="crmCode" value="${command.crmCode}" ltype="text" maxlength="10" validate="{required:true, notnull:true}" nullText="不能为空" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> />
                </td>
            </tr>
            <tr>
                <td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">开放日期起:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                <c:if test="${viewType!='detail'}">
                	<input name="dateF" type="text" id="dateF" value="${command.dateF}" ltype="date" format="yyyy-MM-dd" validate="{required:true, notnull:true}" nullText="不能为空" />
                </c:if>
                <c:if test="${viewType=='detail'}">
                	<input type="text" value="${command.dateF}" disabled="disabled"/>
                </c:if>
                </td>
                  <td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">开放日期止:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                <c:if test="${viewType!='detail'}">
                	<input name="dateT" type="text" id="dateT" value="${command.dateT}" ltype="date" format="yyyy-MM-dd" validate="{required:true, notnull:true}" nullText="不能为空" />
                </c:if>
                <c:if test="${viewType=='detail'}">
                	<input type="text" value="${command.dateT}" disabled="disabled"/>
                </c:if>
                </td>
            </tr>
            <tr>
                <td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">教室名称:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                	<input name="crmTitle" type="text" id="crmTitle" value="${command.crmTitle}" validate="{required:true, notnull:true}" nullText="不能为空" maxlength="50" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
                <td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">教室地址:</td>
                <td style=" padding-bottom: 0px;width:35%;" align="left" class="l-table-edit-td">
                	<input name="crmAddress" type="text" id="crmAddress" value="${command.crmAddress}" validate="{required:true, notnull:true}" nullText="不能为空" maxlength="200" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
            </tr>
        </table>
		
		<table class="tableout" border="1" style="width:80%; margin:15px auto;"><tr><td>
        <table class="l-table-edit" style="width: 100%; margin:10px auto;">
            <tr>
                <td style=" padding-bottom: 0px;width:30%;" align="right" class="l-table-edit-td">星期数</td>
                <td style=" padding-bottom: 0px;width:30%;" align="left" class="l-table-edit-td">
                	<select name="weekT" id="weekT" style="width:50px;" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>
                		<option value="1" ${command.weekT eq 1 ? "selected" : ""}>日</option> 
                		<option value="2" ${command.weekT eq 2 ? "selected" : ""}>一</option>
                		<option value="3" ${command.weekT eq 3 ? "selected" : ""}>二</option>
                		<option value="4" ${command.weekT eq 4 ? "selected" : ""}>三</option>
                		<option value="5" ${command.weekT eq 5 ? "selected" : ""}>四</option>
                		<option value="6" ${command.weekT eq 6 ? "selected" : ""}>五</option>
                		<option value="7" ${command.weekT eq 7 ? "selected" : ""}>六</option>
                	</select> 
                	至
                	<select name="weekF" id="weekF" style="width:50px;" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>
                		<option value="1" ${command.weekF eq 1 ? "selected" : ""}>日</option> 
                		<option value="2" ${command.weekF eq 2 ? "selected" : ""}>一</option>
                		<option value="3" ${command.weekF eq 3 ? "selected" : ""}>二</option>
                		<option value="4" ${command.weekF eq 4 ? "selected" : ""}>三</option>
                		<option value="5" ${command.weekF eq 5 ? "selected" : ""}>四</option>
                		<option value="6" ${command.weekF eq 6 ? "selected" : ""}>五</option>
                		<option value="7" ${command.weekF eq 7 ? "selected" : ""}>六</option>
                	</select> 
                </td>
                <td style=" padding-bottom: 0px;width:12%;" align="right" class="l-table-edit-td">课节数：</td>
                <td style=" padding-bottom: 0px;width:30%;" align="left" class="l-table-edit-td">
                	<select name="crmClassNum" id="crmClassNum" style="width:50px;" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>>
                		<option value="1" ${command.crmClassNum eq 1 ? "selected" : ""}>1</option>
                		<option value="2" ${command.crmClassNum eq 2 ? "selected" : ""}>2</option>
                		<option value="3" ${command.crmClassNum eq 3 ? "selected" : ""}>3</option>
                		<option value="4" ${command.crmClassNum eq 4 ? "selected" : ""}>4</option>
                		<option value="5" ${command.crmClassNum eq 5 ? "selected" : ""}>5</option>
                		<option value="6" ${command.crmClassNum eq 6 ? "selected" : ""}>6</option>
                		<option value="7" ${command.crmClassNum eq 7 ? "selected" : ""}>7</option>
                		<option value="8" ${command.crmClassNum eq 8 ? "selected" : ""}>8</option>
                		<option value="9" ${command.crmClassNum eq 9 ? "selected" : ""}>9</option>
                		<option value="10" ${command.crmClassNum eq 10 ? "selected" : ""}>10</option>
                	</select>
                </td>
            </tr>
        </table>  
        
		<table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 70%; margin-left:85px; margin-top:10px; margin-bottom:10px;">
			<tr>
            	<td style=" padding-bottom: 0px;width:15%;" align="right" class="l-table-edit-td">课节</td>
            	<td style=" padding-bottom: 0px;width:30%;" align="center" class="l-table-edit-td" colspan="4">开始时间</td>
            	<td style=" padding-bottom: 0px;width:30%;" align="center" class="l-table-edit-td" colspan="4">结束时间</td>
            </tr>
			<c:forEach items="${btables}" var="btable" varStatus="status">
      	    <tr id="cls-${status.count}">
            	<td align="right" class="l-table-edit-td" valign="top" style="padding-bottom: 0px;width:15%;">
            		第
            		<c:choose>
            			<c:when test="${1 eq status.count}">一</c:when>
            			<c:when test="${2 eq status.count}">二</c:when>
            			<c:when test="${3 eq status.count}">三</c:when>
            			<c:when test="${4 eq status.count}">四</c:when>
            			<c:when test="${5 eq status.count}">五</c:when>
            			<c:when test="${6 eq status.count}">六</c:when>
            			<c:when test="${7 eq status.count}">七</c:when>
            			<c:when test="${8 eq status.count}">八</c:when>
            			<c:when test="${9 eq status.count}">九</c:when>
            			<c:when test="${10 eq status.count}">十</c:when>
            		</c:choose>
            		节
            	</td>
            	<td style="padding-bottom: 0px;width:10%;" align="right"> 
          		<c:choose>
           			<c:when test="${not empty btable.time_start}">
					<fmt:formatDate pattern="HH" value="${btable.time_start}" var="timeHourStart"/>
          			<input type="text" name="cls-start-hour-${status.count}" value="${timeHourStart}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/> 
           			</c:when>
           			<c:otherwise>
					<input type="text" name="cls-start-hour-${status.count}" value="00" />
					</c:otherwise>
           		</c:choose>
            	</td>
            	<td style="padding-bottom: 0px;width:5%;">時</td>
            	<td style="padding-bottom: 0px;width:10%;" align="right">
           		<c:choose>
           			<c:when test="${not empty btable.time_start}">
           			<fmt:formatDate pattern="mm" value="${btable.time_start}" var="timeMinStart"/>
          			<input type="text" name="cls-start-min-${status.count}" value="${timeMinStart}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/> 
           			</c:when>
           			<c:otherwise>
       				<input type="text" name="cls-start-min-${status.count}" value="00" />
           			</c:otherwise>
           		</c:choose>
            	</td>
            	<td style="padding-bottom: 0px;width:5%;">分</td>
            	<td style="padding-bottom: 0px;width:10%;" align="right">
           		<c:choose>
           			<c:when test="${not empty btable.time_end}">
           			<fmt:formatDate pattern="HH" value="${btable.time_end}" var="timeHourEnd"/>
           			<input type="text" name="cls-end-hour-${status.count}" value="${timeHourEnd}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> /> 
           			</c:when>
           			<c:otherwise>
					<input type="text" name="cls-end-hour-${status.count}" value="00" />
					</c:otherwise>
           		</c:choose>
				</td>
            	<td style="padding-bottom: 0px;width:5%;">時</td>
            	<td style="padding-bottom: 0px;width:10%;" align="right">
           		<c:choose>
           			<c:when test="${not empty btable.time_end}">
     			    <fmt:formatDate pattern="mm" value="${btable.time_end}" var="timeMinEnd"/>
           			<input type="text" name="cls-end-min-${status.count}" value="${timeMinEnd}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> /> 
           			</c:when>
           			<c:otherwise>
					<input type="text" name="cls-end-min-${status.count}" value="00" />
					</c:otherwise>
           		</c:choose>
            	</td>
            	<td style="padding-bottom: 0px;width:5%;">分</td>
            </tr>
            </c:forEach>
		</table>
		</td></tr></table> 		 
    </form>
</body>
</html>
